/*******************************************************************************
	Key programs to install:
	
	egen, egenmore, renvars, reclink, metareg, mgen, collin
	
	
	
	Updates
		4/27 - V3 covariates; updated teacher synth data
	
*******************************************************************************/
	

/*******************************************************************************
	set directory paths
*******************************************************************************/
	
	global base 	"/Users/markjchin/Dropbox/iat_seda_ocr/iat_seda_ocr" // Mark's path
	global logs 	"$base/logfiles"
	global programs	"$base/programs"	
	global raw	 	"$base/raw" 	
	global data		"$base/data" 	
	global output	"$base/output"	
	global graphs	"$base/graphs"	
	
/*******************************************************************************
	set globals
*******************************************************************************/
	
	global estimatemrp = 1
	// Set this to 1 if you need a reminder to pause the master.do to estimate MRP bias scores in R

/*******************************************************************************
	prepare data
*******************************************************************************/

	// Create LEAID-County xwalk using SEDA crosswalk v3.0
	do "$programs/cr-county-leaid-xwalk 4_28_2020.do"

	// SEDA Gaps data
	do "$programs/cr-seda-gaps 2_5_2020.do"
	
		// Creates county-level SEDA gap data
	
	// SEDA Covariates data - use v3.0 and v2.1
	do "$programs/cr-covariates 4_28_2020.do"
	
		// Creates county-level covariate data
	
	// IAT
	do "$programs/cr-iat-data-set 2_11_2020.do" 
	
		// Creates:
		//	- Respondent-level IAT data
		//	- Dataset for estimating county-level bias (pooled)
		//	- Dataset for estimating county-level bias (teacher)

	// Estimate unadjusted bias scores
	do "$programs/cr-bias 2_5_2020.do"
	
		// Creates unadjusted county-level bias scores
		
	// Synthetic County Datasets
	do "$programs/cr-synth-county 2_5_2020.do"	
		
		// Uses 2015 5-year ACS to create Synthetic Counties based on the marginal distributions 
		
	do "$programs/cr-synth-county-tch 4_27_2020.do"
		
		// Uses data from states on teacher demographics to create Synthetic Counties
	
	// Estimate MrP Bias scores
		
		// Break the code to toggle R
		if $estimatemrp == 1 {
			s
			}
			
		// Run cr-estimate-mrp in R.
	
	// Prepare the MrP Bias scores for use 
	do "$programs/cr-mrp-data 2_5_2020.do"
	
		// Creates county-level dataset with MRP scores and counts for IAT data; replaces missing those without data from nonadjusted models
	
	// Prep OCR data
	do "$programs/cr-clean-ocr 2_5_2020.do"
	
		// Cleans the OCR data to create LEA and school level data
		
	do "$programs/cr-susprates 2_5_2020.do"
	
		// Makes a clean panel dataset 2012-2016 for suspension outcomes; also collapses to county level

	// Create common samples for analysis
	do "$programs/cr-commonsamp 2_5_2020.do"
	
		// Makes a common sample crosswalk for counties
	
/*******************************************************************************
	Analysis
*******************************************************************************/
	
	// Descriptives
	do "$programs/an-descriptives 2_5_2020.do"
	
	// SEDA Gap
	do "$programs/an-seda-gaps 2_5_2020.do"
	
	// OCR
	do "$programs/an-ocr 2_5_2020.do"
	
	// IAT Analysis
	do "$programs/an-iat 2_5_2020.do"

/*******************************************************************************
	Sensitivity analyses
*******************************************************************************/
	
	// IAT Analysis - full sample
	do "$programs/an-iat-sensitivity 2_5_2020.do"
	
	// IAT Analysis - K12 vs not
	do "$programs/an-iat-k12vnot 2_5_2020.do"

	// OCR - cluster/full sample/state FE
	do "$programs/an-ocr-sensitivity 2_5_2020.do"
	
	// Different OCR models (risk difference; frac response)
	do "$programs/an-ocr-sensitivity-models 2_5_2020.do"
	
	// Compare samples based on ACS data
	do "$programs/an-samples-alt 2_5_2020.do"

	// Collinearity of variables?
	do "$programs/an-collinearity 2_5_2020.do"
	
	// SEDA Gap - cluster/full sample
	do "$programs/an-seda-gaps-sensitivity 2_5_2020.do"
	
